//
//  MainViewController.swift
//  sinaBlog
//
//  Created by tianxiangyang on 15/12/12.
//  Copyright (c) 2015年 itcast. All rights reserved.
//

import UIKit

class MainViewController: UITabBarController {

    //自定义tabBar
    let mainTabBar = MainTabBar()
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        setValue(mainTabBar, forKey: "tabBar")
        
        addChildViewControllers()
        
        //为compose添加点击事件
        mainTabBar.compose.addTarget(self, action: "composeBtnClick", forControlEvents: UIControlEvents.TouchUpInside)
        
        
        
    }
    
    
    func composeBtnClick(){
    
    print("点击了compose按钮")
        
    }
    
    
    
    private func  addChildViewControllers() {
        
        mainTabBar.tintColor = themeColor()
        
        mainTabBar.backgroundImage = UIImage(named: "tabbar_background")
        
//        mainTabBar.bringSubviewToFront(self.view)

        getViewController(HomeViewController(), title: "首页", imageName: "tabbar_home")
        getViewController(DiscoverViewController(), title: "发现", imageName: "tabbar_discover")
        getViewController(MessageController(), title: "消息", imageName: "tabbar_message_center")
        getViewController(SelfController(), title: "我", imageName: "tabbar_profile")
        
    
    }
    
    private func getViewController(vc:UIViewController,title:String,imageName:String){
    
        
        vc.title = title
    
        vc.tabBarItem.image = UIImage(named: imageName)
        

        let nav = UINavigationController(rootViewController: vc)
        
        addChildViewController(nav)
        
    
    }
    

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    


}
